<?php

namespace app\teacher\model;

use app\common\model\RemindOrder as RemindOrderModel;
use think\Model;

class RemindOrder extends RemindOrderModel
{
    public function user()
    {
        return $this->hasOne(User::class, 'user_id', 'user_id')->field('user_id, nickname, avatar, mobile');

    }

    /**
     * 最新消息
     */
    public static function getByTeacherId($teacherId)
    {
        return self::where('teacher_id', $teacherId)->whereIn('type', [2,6,7,8])->order('createtime desc')->find();
    }

    /**
     * 是否有未读
     */
    public static function getReadingByTeacherId($teacherId)
    {
        return self::where('teacher_id', $teacherId)->where('teacher_reading', 0)->whereIn('type', [2,6,7,8])->count();
    }

    /**
     * 教师课程提醒
     */
    public static function getAllByTeacherId($teacherId, $size = 20)
    {
        return self::with(['courseOrder' => function ($query) {
            $query->with(['teacherCourse' => function ($query) {
                $query->with(['language'])->withCount('course');
            }]);
        }, 'user'])->where('teacher_id', $teacherId)->whereIn('type', [2,6,7,8])->order('createtime desc')->paginate($size);
    }
}
